// pages/dingdan/dingdan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderList: [],
    status: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    this.getOrderList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onChange(e) {
    this.setData({
      status: e.detail.name
    })
    this.getOrderList({
      status: e.detail.name
    });
  },
  
  // 获取订单列表
  getOrderList() {
    let params = {};
    if(this.data.status!==0) {
      params.status = this.data.status;
    }
    wx.$http.post(wx.$api.fetchOrderList, params).then(res => {
      this.setData({
        orderList: res.data || []
      })
    })
    .catch(err => {
      wx.showToast({
        title: err
      })
    })
  },
  // 删除订单
  delOrder(e) {
    const that = this;
    wx.showModal({
      title: "提示",
      content: "是否删除当前订单？",
      success() {
        wx.$http.post(wx.$api.fetchOrderDel, {id: e.currentTarget.dataset.id}).then(res => {
          that.getOrderList();
          wx.showToast({
            title: '删除成功',
            icon: "none"
          })
        })
        .catch(err => {
          wx.showToast({
            title: '删除失败',
          })
        })
      }
    })
  }
})